<!DOCTYPE html>
<html lang="en">
<head>
    <title>公司管理层-陪同拜访</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=4a6c1b54">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style>
        td{
            position: relative;
        }
        .tryStyle{
            width: 30px;
            height: 14px;
            line-height: 14px;
            font-size: 12px;
            /* top: 0; */
            right: 0;
            position: absolute;
            border-radius: 5px;
            margin-top: 1px;
            background: red;
            color: #fff;
            margin-right: 5px;
            transform: scale(0.8);
        }
        .userStyle{
            background: rgba(34,139,238,0.2);
        }
        .row {
            margin-right: -15px;
            margin-left: 0px;
        }
        .col-lg-6,.col-xs-6,.col-md-6{
            padding-left: 0;
        }
    </style>
</head>
<body>
<section class="content" id="app">

    <div class="row">
        <table style="max-width: 660px" class="table table-bordered text-center" id="myTable">
            <thead>
            <tr>
                <th style="width: 50px;text-align: center">排名<br><span v-if="hour<12&&dateTime==today">(昨日)</span></th>
                <th style="width: 70px;text-align: center">大区经理</th>
                <th style="width: 70px;text-align: center">大区</th>
                <th style="width: 75px;text-align: center">
                    陪跑区域<br>经理<span v-if="hour<12&&dateTime==today">(昨日)</span>
                </th>
                <th style="width: 75px;text-align: center">
                    陪跑客户<br>数量<span v-if="hour<12&&dateTime==today">(昨日)</span>
                </th>
                <th style="text-align: center">区域</th>
            </tr>
            </thead>
            <tbody   v-cloak>
            <tr v-for="(item,i) in list">
                <td :rowspan="item.sortspan" :class="{hidden: item.sortdis}" style="text-align: center" >{{item.rownum}}</td>
                <td :rowspan="item.managerNamespan" :class="{hidden: item.managerNamedis}" style="text-align: center">{{item.managerName}}</td>
                <td :rowspan="item.departNamespan" :class="{hidden: item.departNamedis}" style="text-align: center" >{{item.departName}}</td>
                <td style="text-align: center;" :class="item.entourageName=='无'?'userStyle':''">{{item.entourageName}}<span v-if="item.jobState==-2" class="tryStyle">试岗</span><span v-if="item.jobState==-1" class="tryStyle">试用</span></td>
                <td v-if="isGo(item)" style="color:#169BD5;cursor: pointer;text-align: center" @click="lookRegionList(item)" :class="item.entourageName=='无'?'userStyle':''">{{item.visitCount}}</td>
                <td v-else style="text-align: center" :class="item.entourageName=='无'?'userStyle':''">{{item.visitCount}}</td>
                <td style="text-align: left" :class="item.entourageName=='无'?'userStyle':''">{{item.regionName}}</td>
            </tr>
            <tr v-if="list.length!=0"><td>合计</td><td>-</td><td>-</td><td>-</td><td>{{allCount}}</td><td>-</td></tr>
            </tbody>
        </table>
        <div v-if="list.length==0" style="max-width: 660px;text-align: center;"  v-cloak>{{dateTime==today?hour<12?"昨日暂无跑动数据，请12点后查看今日跑动数据":"今日暂无跑动数据":"该月暂无跑动数据"}}</div>
    </div>
    <!-- /.box-body -->
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=602456c3"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=6348cbbc"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript" src="/dist/plugins/highcharts/highcharts.js"></script>
<script type="text/javascript">
    console.log(urlConfig);
    var app = new Vue({
        el: '#app',
        data: {
            currentUser: getCurrentUser(),
            list: [],
            months: [],
            userId: getCurrentUser().id,
            dateTime:$.wyui.page.urlParams.dateTime,
            today:new Date().Format("yyyy-MM-dd"),
            hour:new Date().getHours(),
            companyId:$.wyui.page.urlParams.companyId,
            isToday: "1",
            allCount:""
        },
        methods: {
            //  查看下属
            lookRegionList:function (item) {
                var that = this;

                url = "/page/reportForm/interview/accompanyInterviewList.html?userId="+item.managerId+"&dateTime="+that.dateTime+"&entourage="+item.entourageName;
//                window.open(url + '?userId=' + item.managerId+"&dateTime="+this.dateTime+"&name="+item.managerName, "", "top=50,left=" + (window.screen.width - 10 - 1000) / 2 + ",width=1000,height=600");
                $.dialog({
                    content: 'url:'+url,
                    title: '陪跑列表',
                    width: 600,
                    height: 500,
                    max: false,
                    min: false,
                    lock: true
                });
            },
            getLastEndMonth: function (beginYearMonth) {
                var strYear = parseInt(beginYearMonth.substr(0, 4), 10);
                var strMonth = parseInt(beginYearMonth.substr(4, 6), 10);
                if (strMonth - 1 == 0) {
                    strYear -= 1;
                    strMonth = 12;
                } else {
                    strMonth -= 1;
                }
                if (strMonth < 10) {
                    strMonth = "0" + strMonth;
                }
                var monthstr = strYear + "" + strMonth;
                return monthstr;
            },
            getMonths: function () {
                var that = this;
                var dateTime = new Date().Format("yyyyMM");
                for (var i = 0; i < 5; i++) {
                    dateTime = that.getLastEndMonth(dateTime);
                    that.months.push(that.insert_flg(dateTime, "-", "4"))
                }
            },
            insert_flg: function (str, flg, sn) {
                var newstr = "";
                for (var i = 0; i < str.length; i += sn) {
                    var tmp = str.substring(i, i + sn);
                    console.log(tmp)
                    newstr += tmp + flg;
                }
                newstr = newstr.substr(0, newstr.length - 1);
                return newstr;
            },
            tablesMergeCell:function(list){
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            getList: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.crm.customer.getRegionByManageDQ, {
                    "dateTime":that.dateTime,"companyId":that.companyId
                } , function (data) {
                    console.log(data);
                    that.list = that.tablesMergeCell(data);
                    that.allCount=that.getCount(that.list,"visitCount")
                });
            },getCount:function (arr,key) {
                var number=0;
                for (var i = arr.length - 1; i >= 0; i--) {
                    number+=(arr[i][key]&&arr[i][key]!='-'?arr[i][key]:0)

                }
                return number;
            },isGo:function (item) {
                return true;
                if(getCurrentUser().companyName=="滚滚向前"||getCurrentUser().roleName=='销售管理经理'||getCurrentUser().id==item.managerId||getCurrentUser().roleName=='总经理'||getCurrentUser().roleName=='销售总监')  {
                    return true;
                }else{
                    return false;
                }
            }
        },
        mounted: function () {
            //获取前5个月
            this.getMonths();
            var that = this;
            if(!that.companyId){
                that.companyId=getCurrentUser().companyId;
            }
            that.getList();
        }

    });
</script>

</body>
</html>